package com.muje.android.toiletcard;

import java.util.ArrayList;

import android.util.Log;

/**
 * Poker card player class.
 * 
 * @author yeang-shing.then
 * 
 */
public class Player {
	/**
	 * Name of player.
	 */
	public String Name;
	public ArrayList<Card> Cards;
	/**
	 * Drawable icon value in int.
	 */
	public int Icon;

	/**
	 * Default constructor.
	 * 
	 * @param name
	 *            Player name.
	 */
	public Player(String name) {
		this.Name = name;
		this.Cards = new ArrayList<Card>();
	}

	/**
	 * Default constructor.
	 * 
	 * @param name
	 *            Player name.
	 */
	public Player(String name, int icon) {
		this.Name = name;
		this.Cards = new ArrayList<Card>();
		this.Icon = icon;
	}

	protected void action(String cardNumber, String message) {
		
		//remove from backaward is more efficient and possible.
		for (int i = this.Cards.size() - 1; i >= 0; i--) {
			if (this.Cards.get(i).Text.contains(cardNumber)) {
				Log.d("DEBUG", this.Name + " removing " + message + " at " + i);
				this.Cards.remove(i);
				break;
			}
		}

	}

	/**
	 * True if contains toilet key otherwise false.
	 * 
	 * @return
	 */
	public boolean hasToiletKey() {
		
		for (Card card : this.Cards) {
			if (card.Text.contains(Poker.TOILET_NUMBER))
				return true;
		}

		return false;
	}

	/**
	 * Use toilet card.
	 */
	public void goToilet() {
		action(Poker.TOILET_NUMBER, "toilet card");
	}

	/**
	 * Use safety key.
	 */
	public void cancelPunishment() {
		action(Poker.SAFETY_KEY_NUMBER, "safety key");
	}
}